<?php
	class chucvudb
	{
		public function Them($TenChucVu = "", $MaPhongBan = "")
		{
			$sql = "INSERT INTO chucvu(TenChucVu, MaPhongBan)
						   VALUES('$TenChucVu', '$MaPhongBan')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaChucVu = 0, $TenChucVu = "", $MaPhongBan = "")
		{
			$sql = "UPDATE chucvu 
					SET TenChucVu = '$TenChucVu',
						MaPhongBan = '$MaPhongBan' 
					WHERE MaChucVu = $MaChucVu";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function TonTaiTrongNhanVien($MaChucVu = 0)
		{
			$sql = "SELECT * FROM nguoidung WHERE 1";
			if($MaChucVu > 0)
				$sql.= " AND MaChucVu = $MaChucVu";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Xoa($MaChucVu = 0)
		{
			$sql = "DELETE FROM chucvu 
					WHERE MaChucVu = $MaChucVu";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function XoaTatCa()
		{
			$sql = "DELETE FROM chucvu";			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaChucVu = 0, $TenChucVu = "", $MaPhongBan = "")
		{
			$sql = "SELECT * 
					FROM chucvu 
					WHERE 1";
			
			if($MaChucVu > 0)
				$sql .= " AND MaChucVu = $MaChucVu";
				
			if($TenChucVu != "")
				$sql .= " AND TenChucVu = '$TenChucVu'";
				
			if($MaPhongBan != "")
				$sql .= " AND MaPhongBan = '$MaPhongBan'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>